package hot100.h0911;

import java.util.Arrays;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 完全平方数
 * @date 2024/9/11 23:39
 */
public class PerfectSquare {
    public static void main(String[] args) {
        System.out.println(numSquares(12));
    }

    public static int numSquares(int n) {
        int[] dp = new int[n + 1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j * j <= i; j++) {
                dp[i] = Math.min(dp[i], dp[i - j * j] + 1);
            }
        }
        return dp[n];
    }
}
